<template>
	<div class="add_goods"><iframe class="add-goods-iframe" ref="iframe" :src="url" frameborder="0" @load="loaded"></iframe></div>
</template>

<script>
export default {
	data() {
		return {
			admin_type:localStorage.getItem('admin_type'),
			admin_id: localStorage.getItem('admin_id'), // admin_id 理员 1是总号，2是商家，3是厂家，4财务，5招商，6产品，7仓管 8收费厂家 9.外部招商员
			url: '',
			iframeData: null
		};
	},
	watch: {
		iframeData: 'changeiframe'
	},
	methods: {
		init(){
			if(this.admin_type == 1){
				this.url = 'https://jiaju01.cn/jjdss2b/OLD/add_combination.html?key=' + this.key
			}else if(this.admin_id == 3){
				this.url = 'https://jiaju01.cn/jjdss2b/OLD/f_admin/f_add_combination.html?key=' + this.key
			}
		},
		loaded() {
			window.addEventListener('message', e => {
				this.iframeData = e.data;
			});
		},
		changeiframe() {
			this.$router.push({ path: '/goods_list' });
			console.log('Iframe值变化，执行changeiframe' + this.iframeData);
		}
	},
	created() {
		this.init()
	}
};
</script>

<style>
.add_goods {
	width: 100%;
	height: 100%;
}
.add-goods-iframe {
	width: 100%;
	height: 100%;
}
</style>
